package com.example.fx.adapter

import android.annotation.SuppressLint
import android.graphics.drawable.ColorDrawable
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.Child
import com.example.fx.R
import com.example.fx.utils.GlideUtils

/**
 * 二级分类适配器
 */
class TwoAdapter:BaseQuickAdapter<Child,BaseViewHolder>(R.layout.item_two) {
    private var selectId = 534
    @SuppressLint("ResourceAsColor")
    override fun convert(holder: BaseViewHolder, item: Child) {
        GlideUtils.loadImage(context,item.extra,holder.getView(R.id.iv))
        holder.setText(R.id.tv,item.name)
        if(item.id==selectId){
            holder.getView<TextView>(R.id.tv).background = ColorDrawable(R.color.purple_200)
        }else{
            holder.getView<TextView>(R.id.tv).background = null
        }
    }
    //修改选中的id值
    fun setId(id:Int){
        selectId = id
        notifyDataSetChanged()
    }
}